﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.Reports.ReportPages
{
    public partial class AnalysisReport_Page : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int typeid = _Request.GetInt("typeid", 0);          // 1盘源更进 2客源跟进 3待看提醒 4已带看 5新添盘源 6新添客源 7独家 8反签 9钥匙 10查看电话 11上传图片盘源 12上传图片数 13自看房源  
                int deptId = _Request.GetInt("deptid", 0);          // 部门ID
                string deptname = _Request.GetString("deptname", "");
                if (deptId <= 0)
                {
                    deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID, 0);
                    deptname = _Utility.GetInfoBySession().m_sDeptName;
                }

                string startdate = _Request.GetString("startDate", DateTime.Today.ToString("yyyy-MM-dd"));
                string enddate = _Request.GetString("endDate", DateTime.Today.ToString("yyyy-MM-dd"));
                string fgs = _Utility.GetInfoBySession().m_sFgs;

                if (typeid == 1 || typeid == 2)
                {
                    DataSet ds = ZLDC.Topo.BLL.Estate.ReportBLL.GetYejiAnalysis(startdate, enddate, fgs, typeid, deptId);
                    this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("../ReportFiles/AnalysisReport.rdlc");
                    
                    // 添加量化信息
                    this.ReportViewer1.LocalReport.DataSources.Add(
                        new Microsoft.Reporting.WebForms.ReportDataSource("AnalyisisDataSet_detail", ds.Tables["Table"]));


                    // 添加成交盘明细
                    this.ReportViewer1.LocalReport.DataSources.Add(
                        new Microsoft.Reporting.WebForms.ReportDataSource("AnalyisisDataSet_dealpan", ds.Tables["Table1"]));

                    // 房源来源
                    this.ReportViewer1.LocalReport.DataSources.Add(
                        new Microsoft.Reporting.WebForms.ReportDataSource("AnalyisisDataSet_panfrom", ds.Tables["Table2"]));

                    // 客源来源
                    this.ReportViewer1.LocalReport.DataSources.Add(
                        new Microsoft.Reporting.WebForms.ReportDataSource("AnalyisisDataSet_kefrom", ds.Tables["Table3"]));




                    // 添加查询条件  

                    DataTable dt = new DataTable();
                    dt.Columns.Add("querystring");
                    dt.Columns.Add("title");

                    DataRow dr = dt.NewRow();

                    dr["querystring"] = "查询条件：部门[" + deptname + "]   时间：" + startdate + " 至 " + enddate;
                    if (typeid == 1)
                    {
                        dr["title"] = "卖单量化分析";
                    }
                    else
                    {
                        dr["title"] = "租单量化分析";
                    }
                    dt.Rows.Add(dr);

                    this.ReportViewer1.LocalReport.DataSources.Add(
                        new Microsoft.Reporting.WebForms.ReportDataSource("AnalyisisDataSet_querytable", dt));

                }

              

                //显示报表
                this.ReportViewer1.LocalReport.Refresh();
            }
        }        
       
    }
}
